﻿@model ShiXuLong.Model.Shop
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>AddView</title>
    <link href="~/lib/layui/css/layui.css" rel="stylesheet" />

    <script src="~/scripts/jquery-3.5.1.js"></script>
    <style>
        .file {
            position: relative;
            display: inline-block;
            background: #D0EEFF;
            border: 1px solid #99D3F5;
            border-radius: 4px;
            padding: 4px 12px;
            overflow: hidden;
            color: #1E88C7;
            text-decoration: none;
            text-indent: 0;
            line-height: 20px;
        }

            .file input {
                position: absolute;
                font-size: 100px;
                right: 0;
                top: 0;
                opacity: 0;
            }

            .file:hover {
                background: #AADFFD;
                border-color: #78C3F3;
                color: #004974;
                text-decoration: none;
            }
    </style>

</head>
<body>

    <form class="layui-form" id="frmEdit">
        <div class="layui-form-item">
            <label class="layui-form-label">商品编号</label>
            <div class="layui-input-inline">
                <input name="Id" hidden type="text" value="@Model.Id" />
                <input type="text" name="ShopId" value="@Model.ShopId" required lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">商品名称</label>
            <div class="layui-input-inline">
                <input type="text" value="@Model.ShopName" name="ShopName" required lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input">
            </div>
        </div>
        @*<div class="layui-form-item">
                <label class="layui-form-label">商品图片</label>
                <div class="layui-input-inline">
                    <input type="text" value="@Model.Shopimage" name="Shopimage" required lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input">
                </div>
            </div>*@
        <div class="layui-form-item">
            <label class="layui-form-label">商品图片</label>
            <div class="layui-input-inline">
                <img src="@Model.Shopimage" id="image" style="width:161px;height:153px;">
                <input type="text" id="shopImage" name="Shopimage" value="@Model.Shopimage" />
                <a href="javascript:;" class="file">
                    修改图片
                    <input type="file" name="file" id="ModificationImage">
                </a>
            </div>

        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">文本域</label>
            <div class="layui-input-inline">
                <textarea name="ProductProfile" placeholder="请输入内容" class="layui-textarea">@Model.ProductProfile</textarea>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">商品类别</label>
            <div class="layui-input-inline">
                <select name="ShopTypeId" lay-verify="required">
                    @foreach (var item in ViewBag.ShopType)
                    {
                        <option value="@item.Id">@item.ShopTypeName</option>
                    }

                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">推荐位置</label>
            <div class="layui-input-inline">
                <select name="RecommendId" lay-verify="required">

                    <option value="1">1</option>

                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">Display</label>
            <div class="layui-input-inline">
                <input type="text" value="@Model.Display" name="Display" required lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">价格</label>
            <div class="layui-input-inline">
                <input type="text" value="@Model.Price" name="Price" required lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">库存数量</label>
            <div class="layui-input-inline">
                <input type="text" value="@Model.Number" name="Number" required lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">规格</label>
            <div class="layui-input-inline">
                <input type="text" value="@Model.GuideId" name="GuideId" required lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" id="EditSub" lay-filter="formDemo">立即提交</button>
                @*<button type="reset" class="layui-btn layui-btn-primary">重置</button>*@
            </div>
        </div>
    </form>
    <script src="~/lib/layui-v2.5.6/layui/layui.js"></script>

    <script>
        //Demo
        layui.use(['form', 'layer', 'upload'], function () {
            var form = layui.form;
            //var $ = layui.$;
            var layer = layui.layer;
            var upload = layui.upload;
            //action = ""
            $("#EditSub").click(function () {
                var con = $("#frmEdit").serialize();
                $.ajax({
                    url: "/Home/Edit",
                    type: "post",
                    data: con,
                    success: function (res) {
                        layer.msg(res);
                    }
                });
                setTimeout(function () {
                    parent.location.reload();
                    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                    parent.layer.close(index); //再执行关闭
                }, 1000);

                return false;
            });
            var uploadInst = upload.render({
                elem: '#ModificationImage' //绑定元素
                , url: '/Home/UpdateShopImage' //上传接口
                , done: function (res) {
                    //上传完毕回调
                    $("#shopImage").val(res.remark);
                    $("#image").attr("src",   res.remark);
                    console.log(0000);
                }
                , error: function () {
                    //请求异常回调
                    console.log(123);
                }
            });


        });
    </script>

</body>
</html>
